import urllib
from urllib import request
from urllib import parse

# 当访问的URL传入参数过多时，通过quote方法进行传参会很麻烦

url = "http://www.baidu.com/s?"

data = {
    "wd": "大数据",
    "ie":"utf-8"
}

encode_res = parse.urlencode(data).encode('utf-8')
# print(encode_res)

url += str(encode_res)[2:-2]
# print(url)
# print(url.format(encode_res))


headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
}
request_obj = request.Request(url=url, headers=headers)
response = request.urlopen(request_obj)
print(response.read().decode('utf8'))